vimfandomcom-20200223-history
Errorformats
The errorformat (or efm) option is a comma-separated list of scanf-style format strings that are used with QuickFix to extract information like file name, line number, column number, etc, from errors and warnings generated with :make. If an error/warning message in the quickfix window matches one of your error formats, you can select it (double click in gvim, or press Enter on the line) to jump to the correct place. It also provides some simple reformatting and highlighting to standardize the display of recognized messages. Vim comes preloaded with some good defaults. You can use the set errorformat command in (for instance) your vimrc file to add more for tools you use. If you use the += operator for the assignment, it will append the text to the current value, separated with a comma, as required for the errorformat. If some builtin format bugs you, you could be tempted to copy the default errorformat and remove the annoying format (good luck to escape all the must-be-escaped characters). Or you could use the -= operator, e.g. set errorformat-=%f:%l:%m Since compilers and other programs generate messages according to their own rules, there are a multitude of error formats that could be useful. Some are listed here. flex The free alternative to LEX, a lexical parser generator. Error messages are like: "somefile.l", line 15: rule cannot be matched. set errorformat+=%*\"%f%*\"\\,\ line\ %l:\ %m bison The GNU bison parser generator (similar to YACC) generates a couple of different types of errors. They start with the file name, then a colon. If available, the linenumber comes next, followed by a dot (period) and the column number. If appropriate, a dash and then another column number (giving a column range) follows, and then a colon, space, and the error message. set errorformat+=%f:%l.%c-%*0-9:\ %m set errorformat+=%f:%l.%c:\ %m set errorformat+=%f:\ %m Texas Instruments cl2000 compiler This is the C-compiler and linker that's used for some Texas Instruments DSP microprocessors. Error format is like "file.c", line 17: some error message. set errorformat=\"%f\"\\,\ line\ %l:\ %m eslint This common linting utility for Javascript has a few output formats. The compact format outputs a structure similar to the following: /some/dir/fullOfProblems.js: line 3, col 16, Error - Unexpected space before unary operator '++'. (space-unary-ops) /some/dir/fullOfProblems.js: line 3, col 20, Warning - Missing semicolon. (semi) This can be effectively parsed with this 'errorformat' setting: set errorformat+=%f:\ line\ %l\\,\ col\ %c\\,\ %trror\ -\ %m set errorformat+=%f:\ line\ %l\\,\ col\ %c\\,\ %tarning\ -\ %m mingw The mingw Windows port of the gcc c-compiler/linker from the FSF. set errorformat+=%f:%l:\ %m gfortran A suitable 'errorformat' for gfortran is: set efm=%E%f:%l.%c:,%E%f:%l:,%C,%C%p%*0123456789^,%ZError:\ %m,%C%.%# %E%f:%l.%c: to parse "FILENAME:LINENUMBER.COLNUMBER:". %E%f:%l: to parse "FILENAME:LINENUMBER:". %C: to pass over the empty line. %C%p%*0123456789^: to get the column number from the indicator line (" 1"). %ZError:\ %m: to parse the error message ("Error: ERROR_MESSAGE"). %C%.%#: to pass over the source code line (and ignore it). The following allows parsing of the following message (make output): gfortran hello-world.f90 -o hello-world.exe hello-world.f90:11: sprint *, "hello", pi, x, r 1 Error: Unclassifiable statement at (1) hello-world.f90:9.4: r = cotan(pi/2) 1 Error: Function 'cotan' at (1) has no IMPLICIT type make: *** hello-world.exe Error 1 In Vim, :clist then shows: 2 hello-world.f90:11 col 1 error: Unclassifiable statement at (1) 3 hello-world.f90:9 col 4 error: Function 'cotan' at (1) has no IMPLICIT type Where hello-world.f90 is: program hello implicit none real (kind = 10), dimension(10):: r real (kind=8):: pi pi = atan(1.0) * 4 r = cotan(pi/2) sprint *, "hello", pi, x, r end program Modelsim vlog/vcom for Verilog/VHDL A simulation tool for Verilog/VHDL. Error messages look like: ** Error: /pathto/somefile.v(115): near \"source text\": syntax error message. set errorformat=**\ Error:\ %f(%l):\ %m There are some other possible formats as well, including warning and note messages. set errorformat=\*\*\ %tRROR:\ %f(%l):\ %m,\*\*\ %tRROR:\ %m,\*\*\ %tARNING:\ %m,\*\*\ %tOTE:\ %m,%tRROR:\ %f(%l):\ %m,%tARNING\[%*0-9\]:\ %f(%l):\ %m,%tRROR:\ %m,%tARNING\[%*0-9\]:\ %m Zilog Code for the Zilog eZ80 microprocessor can be built from Vim after installing ZDS. Create a makefile manually or use the one generated from a ZDS project. With the following in your vimrc, you can use :Make to perform a :make and to open any resulting quickfix window: command -nargs=* Make make |cwindow 3 Add the following to file ~/.vim/after/ftplugin/c.vim (Unix) or $HOME/vimfiles/after/ftplugin/c.vim (Windows) – you may need to create the file. Then you can press F7 to build: setlocal errorformat=%f\ (%l\\,%c)\ :\ ERROR\ (%n)\ %m setlocal makeef=\myerrs.txt nnoremap :update:Make -f myproject_myconf.mak The errorformat line contains two tab characters (shown as large whitespaces above). :Todo: Should investigate use of :let errorformat=... with \t to avoid need to use literal tab characters. CMake " CMake Parser " Call stack entries let &efm = ' %#%f:%l %#(%m)' " Start of multi-line error let &efm .= ',%E' . 'CMake Error at %f:%l (message):' " End of multi-line error let &efm .= ',%Z' . 'Call Stack (most recent call first):' " Continuation is message let &efm .= ',%C' . ' %m' See also *Errorformat for icc7 *Errorformat for Intel ifort *Errorformat for java/ant/junit/cygwin/bash *Errorformat and makeprg References * * Comments *Clean up tips in Category:Compiler. *Where appropriate, should merge compiler tips for a particular language into one tip. *Need emphasis to be on the :compiler command (don't directly mess with 'efm'). *Settings for errorformat should be in a compiler plugin rather than in vimrc. *If there is no support for a compiler, user should add a new compiler (need example of how). *Need links to a tip with info on the quickfix window. Related tips (all are in Compiler category; first four are in 'see also' above) *476 Errorformat and makeprg *325 Errorformat for java/ant/junit/cygwin/bash *518 Errorformat for icc7 *682 Errorformat for Intel ifort *1107 J2ME development *3 Compile Java with Jikes *120 Compile Java with Sun JDK javac *385 Some Java tips *458 Use the quickfix window to list all errors *280 Integration with PyUnit testing framework *949 Integrate Pylint and Pychecker support *473 Compiler for perl *692 Runtime syntax check for php *443 A better interfacing of (La)TeX with the quickfix mode *852 Make support for NEC V850 CA850 compilers Many existing tips have obsolete/bad advice, for example, tip 476 says to edit the $VIM/ftplugin/perl.vim file (probably means $VIMRUNTIME/ftplugin/perl.vim but you should never patch a distribution file). ----